import Mock from "mockjs";

//所有商品数据
Mock.mock("/getList", () => {
  return Mock.mock({
    code: 200,
    "data|100": [
      {
        id: "@id",
        image: "@image(100x100, @color)"
      }
    ]
  });
});

//商品管理数据
const data = Mock.mock({
  "list|30": [
    {
      id: "@id",
      name: "@cword(10,20)", //商品名称
      img: "@image(100x100)", //图片
      "price|100-300": 0, //售价
      "paynum|100-300": 0, //数量
      "have|100-300": 0, //库存
      "sortnum|100-300": 0, //排序
      "state|1": [false, true], //状态
      timer: '@DATETIME("yyyy-MM-dd HH:mm:ss")' //操作时间
    }
  ]
});
Mock.mock("/getShopAdmin", "post", req => {
  const { pageIndex, pageSize } = JSON.parse(req.body);
  let newList = data.list;
  newList = newList.slice((pageIndex - 1) * pageSize, pageIndex * pageSize);
  return {
    code: 200,
    data: newList,
    total: data.list.length
  };
});

//商品评价数据
Mock.mock("/getShopSay", () => {
  return Mock.mock({
    "list|30-80": [
      {
        id: "@id(5)", //商品id
        title: "@ctitle(4,20)", //商品信息
        img: "@image(20x20,@color)",
        name: "@cname(4)", //用户名称
        num: "5", //商品评分  服务评分
        content: "@ctitle(10,30)", //评价内容
        callmain: "@ctitle(3,10)", //回复内容
        data: '@DATETIME("yyyy-MM-dd HH:mm:ss")' //评价时间
      }
    ]
  });
});

//商品分类数据
Mock.mock("/getShopType", () => {
  Mock.mock({
    "list|50": [
      {
        id: "@id", //id
        type: "产品类型", //类型
        name: "@ctitle", //名称
        img: "@image(100x100,@color)", //图标
        "num|10-100": 0 //排序
      }
    ]
  });
});
//商品规格数据
Mock.mock("/getShopRule", () => {
  return Mock.mock({
    "list|20": [
      {
        id: "@id",
        name: "@cname",
        title: "@ctitle(2,4)",
        "have|10-400": 0
      }
    ]
  });
});

//砍价列表数据
Mock.mock("/getBargainList", () => {
  return Mock.mock({
    "list|10-100": [
      {
        "id|+1": 0, // ID
        img: "@image(100x100,@color)", // 砍价图片
        name: "@cname", // 砍价商品名称
        title: "@ctitle", // 商品介绍
        "price|10-200": 1, // 砍价价格
        "allnum|1-5": 1, // 总砍砍次数
        "residuenum|1-5": 1, // 剩余砍价次数
        begindate: "@date", // 开始时间
        finishdate: "@date", // 结束时间
        flag: "@boolean" // 砍价状态开关
      }
    ]
  });
});



const data1 = Mock.mock({
  "list|30-50": [
    {
      id: "@id",
      name: "@cname",
      "newprice|5-100": 5,
      "oldprice|1-5": 1,
      "num|0-10": 0,
      "num1|0-10": 0,
      "num2|0-10": 0,
      "num3|20-100": 20,
      'stateFlag|1':[false,true],
      img: "@image(100x100,@color)"
    }
  ]
});
Mock.mock("/getKshop", "post", req => {
  const { pageIndex, pageSize } = JSON.parse(req.body);
  let newList = data1.list;
  newList = newList.slice((pageIndex - 1) * pageSize, pageIndex * pageSize);
  return {
    code: 200,
    data: newList,
    total: data1.list.length
  };
});
